<html>
<head><meta charset="utf-8"><title>Stdin enhancements · t-libs · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/index.html">t-libs</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Stdin.20enhancements.html">Stdin enhancements</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="244363612"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Stdin%20enhancements/near/244363612" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Yu [they/she] <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Stdin.20enhancements.html#244363612">(Jun 29 2021 at 23:58)</a>:</h4>
<p>sorry, i haven't really done a libstd enhancement proposal before, so i'm not quite sure how this works; has anyone had a chance to look at <a href="https://github.com/rust-lang/rust/pull/86412">https://github.com/rust-lang/rust/pull/86412</a> ? does it need a tracking issue? or maybe other more visible call for feedback?</p>



<a name="244374058"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Stdin%20enhancements/near/244374058" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Stdin.20enhancements.html#244374058">(Jun 30 2021 at 03:35)</a>:</h4>
<p>I just posted a comment to that.</p>



<a name="244374118"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Stdin%20enhancements/near/244374118" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Stdin.20enhancements.html#244374118">(Jun 30 2021 at 03:36)</a>:</h4>
<p>I'd <em>love</em> to see public methods <code>Stdin::locked()</code> and <code>Stdout::locked()</code> and <code>Stderr::locked()</code>. If those came with documentation and tests, I'd r+ those right now.</p>



<a name="244374136"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Stdin%20enhancements/near/244374136" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Stdin.20enhancements.html#244374136">(Jun 30 2021 at 03:36)</a>:</h4>
<p>That doesn't get us all the way to <code>std::io::stdin().lines()</code>, but it'd give us <code>std::io::stdin().locked().lines()</code>, which is slightly longer but more general.</p>



<a name="244374146"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Stdin%20enhancements/near/244374146" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Stdin.20enhancements.html#244374146">(Jun 30 2021 at 03:37)</a>:</h4>
<p>And it also gives us <code>let stdin = std::io::stdin().locked();</code>, which is almost always what I end up wanting.</p>



<a name="244374201"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Stdin%20enhancements/near/244374201" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Stdin.20enhancements.html#244374201">(Jun 30 2021 at 03:38)</a>:</h4>
<p><span class="user-mention" data-user-id="411291">@Taylor Yu [they/she]</span> Would you be interested in adding those? I'd be happy to walk you through the process, including the tracking issue.</p>



<a name="244443774"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Stdin%20enhancements/near/244443774" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Yu [they/she] <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Stdin.20enhancements.html#244443774">(Jun 30 2021 at 15:40)</a>:</h4>
<p>thanks for the feedback! i commented on the PR, probably at more length than i had intended; sorry about that</p>



<a name="244654924"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Stdin%20enhancements/near/244654924" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Yu [they/she] <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Stdin.20enhancements.html#244654924">(Jul 02 2021 at 02:59)</a>:</h4>
<p>new PR: <a href="https://github.com/rust-lang/rust/pull/86799">https://github.com/rust-lang/rust/pull/86799</a> for owned locked stdio handles</p>



<a name="244655749"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Stdin%20enhancements/near/244655749" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Stdin.20enhancements.html#244655749">(Jul 02 2021 at 03:18)</a>:</h4>
<p>Posted a review. Thanks for working on this!</p>



<a name="245699876"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Stdin%20enhancements/near/245699876" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Yu [they/she] <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Stdin.20enhancements.html#245699876">(Jul 12 2021 at 15:09)</a>:</h4>
<p><span class="user-mention" data-user-id="239881">@Josh Triplett</span> if you have a chance to look at <a href="https://github.com/rust-lang/rust/pull/86846">https://github.com/rust-lang/rust/pull/86846</a> (add tracking issue number to feature gates) and <a href="https://github.com/rust-lang/rust/pull/86847">https://github.com/rust-lang/rust/pull/86847</a> (Stdin forwarders), that would be great!</p>



<a name="245705174"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Stdin%20enhancements/near/245705174" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Stdin.20enhancements.html#245705174">(Jul 12 2021 at 15:46)</a>:</h4>
<p>Just r+ed the former.</p>



<a name="245705421"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Stdin%20enhancements/near/245705421" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Yu [they/she] <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Stdin.20enhancements.html#245705421">(Jul 12 2021 at 15:48)</a>:</h4>
<p>if you want me to add a tracking issue for the latter, i can do that and then ping you when i'm done</p>



<a name="245705538"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Stdin%20enhancements/near/245705538" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Stdin.20enhancements.html#245705538">(Jul 12 2021 at 15:49)</a>:</h4>
<p>For the latter, I'm a little torn. On the one hand, I want to make standard input easier to use. On the other hand, now that the new into_locked method exists, people really can just write these as one-liners.</p>



<a name="245705762"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Stdin%20enhancements/near/245705762" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Stdin.20enhancements.html#245705762">(Jul 12 2021 at 15:50)</a>:</h4>
<p>I can understand, though, that the locking <em>concept</em> may be adding complexity. I don't know how much of that is avoidable by just not making someone call a method with lock in the name.</p>



<a name="245705878"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Stdin%20enhancements/near/245705878" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Stdin.20enhancements.html#245705878">(Jul 12 2021 at 15:51)</a>:</h4>
<p>I'm not strongly opposed, but I also wonder how much these forwarders will help, above and beyond <code>into_locked</code>.</p>



<a name="245705929"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Stdin%20enhancements/near/245705929" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Yu [they/she] <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Stdin.20enhancements.html#245705929">(Jul 12 2021 at 15:52)</a>:</h4>
<p>we do have precedent in the <code>read_line</code> forwarder, and the implicitly locking <code>Read</code> implementation. and <code>lines</code> is arguably easier to use in some ways than <code>read_line</code></p>



<a name="245705974"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Stdin%20enhancements/near/245705974" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Stdin.20enhancements.html#245705974">(Jul 12 2021 at 15:52)</a>:</h4>
<p>(regardless, I do think those methods should have a separate tracking issue, assuming we add them)</p>



<a name="245706543"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Stdin%20enhancements/near/245706543" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Stdin.20enhancements.html#245706543">(Jul 12 2021 at 15:56)</a>:</h4>
<p>Hmmm, that's a good point...</p>



<a name="245707271"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Stdin%20enhancements/near/245707271" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Stdin.20enhancements.html#245707271">(Jul 12 2021 at 16:00)</a>:</h4>
<p>Alright, given that we already have read_line, I don't see an issue with these. Can you please file a separate library tracking issue (feature gate <code>stdin_forwarders</code> or similar)?</p>



<a name="245707542"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Stdin%20enhancements/near/245707542" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Stdin.20enhancements.html#245707542">(Jul 12 2021 at 16:02)</a>:</h4>
<p>Also, once they're merged, could you please post on the users forum and/or Reddit, trying to get people to try it out, and especially asking for feedback from recent adopters of Rust?</p>



<a name="245707622"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Stdin%20enhancements/near/245707622" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Stdin.20enhancements.html#245707622">(Jul 12 2021 at 16:03)</a>:</h4>
<p>I'll just say that neither of these are methods I'd ever use myself.</p>
<p>What I want as a user is a way to get it locked as a one-liner, <em>but stop allocating on my behalf so much</em>.</p>



<a name="245707720"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Stdin%20enhancements/near/245707720" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Yu [they/she] <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Stdin.20enhancements.html#245707720">(Jul 12 2021 at 16:03)</a>:</h4>
<p>so <code>lines</code> would be counterproductive for your goals because it does a lot of allocations?</p>



<a name="245707811"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Stdin%20enhancements/near/245707811" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Stdin.20enhancements.html#245707811">(Jul 12 2021 at 16:04)</a>:</h4>
<p>Right, i want the form that takes &amp;mut String and fills it with the message</p>



<a name="245707902"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Stdin%20enhancements/near/245707902" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Stdin.20enhancements.html#245707902">(Jul 12 2021 at 16:05)</a>:</h4>
<p><span class="user-mention" data-user-id="224471">@Lokathor</span> so, you would want to call into_locked and then read lines one at a time into the same String buffer?</p>



<a name="245707953"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Stdin%20enhancements/near/245707953" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Stdin.20enhancements.html#245707953">(Jul 12 2021 at 16:05)</a>:</h4>
<p>yes</p>



<a name="245708031"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Stdin%20enhancements/near/245708031" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Stdin.20enhancements.html#245708031">(Jul 12 2021 at 16:06)</a>:</h4>
<p>That seems like something the optimizer could theoretically do, assuming you stop looking at the previous String by the time you get the next one.</p>



<a name="245708243"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Stdin%20enhancements/near/245708243" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Stdin.20enhancements.html#245708243">(Jul 12 2021 at 16:07)</a>:</h4>
<p>Well I'm sure that a "sufficiently smart compiler" can handle it, but I'm also very confident we won't see such a thing for quite some time, if ever</p>



<a name="245708264"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Stdin%20enhancements/near/245708264" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Stdin.20enhancements.html#245708264">(Jul 12 2021 at 16:07)</a>:</h4>
<p>No argument there.</p>



<a name="245708363"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Stdin%20enhancements/near/245708363" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Stdin.20enhancements.html#245708363">(Jul 12 2021 at 16:08)</a>:</h4>
<p>Also, cc <span class="user-mention" data-user-id="220717">@Bart Massey</span> or <span class="user-mention" data-user-id="317761">@Bart Massey</span> (not sure which one is the right account), who teaches Rust to his students.</p>



<a name="245708506"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Stdin%20enhancements/near/245708506" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Stdin.20enhancements.html#245708506">(Jul 12 2021 at 16:08)</a>:</h4>
<p>Would <code>into_locked</code> and/or <code>lines</code> help your students?</p>



<a name="245708512"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Stdin%20enhancements/near/245708512" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Stdin.20enhancements.html#245708512">(Jul 12 2021 at 16:09)</a>:</h4>
<p>The bigger problem I've had myself, which doesn't get handled by these changes, is that when I'm trying to prompt the user for input and then get a reply back i have to manipulate stdin but <em>also</em> stdout because stdout flushes in line mode by default</p>



<a name="245708761"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Stdin%20enhancements/near/245708761" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Yu [they/she] <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Stdin.20enhancements.html#245708761">(Jul 12 2021 at 16:10)</a>:</h4>
<p>yeah part of why i wanted <code>lines</code> is making a loop prompting for input, but not repeating the code that prints the prompt. otherwise i could <code>for line in io::stdin().lock().lines()</code> and be done with it (because the temporary won't get dropped until the end of the loop body)</p>



<a name="245708886"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Stdin%20enhancements/near/245708886" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Stdin.20enhancements.html#245708886">(Jul 12 2021 at 16:11)</a>:</h4>
<p>So how would you write that now?</p>



<a name="245709082"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Stdin%20enhancements/near/245709082" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Stdin.20enhancements.html#245709082">(Jul 12 2021 at 16:12)</a>:</h4>
<p>My "quick and dirty" function for prompt and get input ended up being like this: &lt;<a href="https://github.com/Lokathor/stdgame/blob/main/src/main.rs#L10-L25">https://github.com/Lokathor/stdgame/blob/main/src/main.rs#L10-L25</a>&gt;, though here I'm also returning String still.</p>



<a name="245709226"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Stdin%20enhancements/near/245709226" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Yu [they/she] <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Stdin.20enhancements.html#245709226">(Jul 12 2021 at 16:13)</a>:</h4>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="kd">let</span><span class="w"> </span><span class="n">lines</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">io</span>::<span class="n">stdin</span><span class="p">().</span><span class="n">lines</span><span class="p">();</span><span class="w"></span>
<span class="c1">// before, let lines = io::stdin().lock().lines() would get a lifetime error</span>
<span class="k">loop</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="fm">print!</span><span class="p">(</span><span class="s">"prompt: "</span><span class="p">);</span><span class="w"></span>
<span class="w">    </span><span class="n">io</span>::<span class="n">stdout</span><span class="p">().</span><span class="n">flush</span><span class="p">();</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">line</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">lines</span><span class="p">.</span><span class="n">next</span><span class="p">();</span><span class="w"></span>
<span class="w">    </span><span class="c1">// do stuff</span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="245709297"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Stdin%20enhancements/near/245709297" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Stdin.20enhancements.html#245709297">(Jul 12 2021 at 16:14)</a>:</h4>
<p>note that print<strong>ln</strong> will flush</p>



<a name="245709404"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Stdin%20enhancements/near/245709404" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Yu [they/she] <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Stdin.20enhancements.html#245709404">(Jul 12 2021 at 16:15)</a>:</h4>
<p>oops, fixed</p>



<a name="245709650"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Stdin%20enhancements/near/245709650" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Stdin.20enhancements.html#245709650">(Jul 12 2021 at 16:16)</a>:</h4>
<p>now what's also unfortunate here is that the lines iterator doesn't work on windows :P</p>



<a name="245709678"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Stdin%20enhancements/near/245709678" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Yu [they/she] <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Stdin.20enhancements.html#245709678">(Jul 12 2021 at 16:16)</a>:</h4>
<p>it doesn't? what goes wrong?</p>



<a name="245709753"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Stdin%20enhancements/near/245709753" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Stdin.20enhancements.html#245709753">(Jul 12 2021 at 16:16)</a>:</h4>
<p>it cuts the <code>\n</code> but ignores the <code>\r</code></p>



<a name="245709782"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Stdin%20enhancements/near/245709782" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Stdin.20enhancements.html#245709782">(Jul 12 2021 at 16:17)</a>:</h4>
<p>so you don't get properly split lines</p>



<a name="245711779"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Stdin%20enhancements/near/245711779" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Yu [they/she] <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Stdin.20enhancements.html#245711779">(Jul 12 2021 at 16:29)</a>:</h4>
<p>it does? <a href="https://doc.rust-lang.org/src/std/io/mod.rs.html#2571-2576">https://doc.rust-lang.org/src/std/io/mod.rs.html#2571-2576</a> seems to show it also trims <code>\r</code></p>



<a name="245713641"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Stdin%20enhancements/near/245713641" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Stdin.20enhancements.html#245713641">(Jul 12 2021 at 16:43)</a>:</h4>
<p>hmmmm... oh, my mistake, it's <em>only</em> read_line which does this thing: &lt;<a href="https://doc.rust-lang.org/std/io/trait.BufRead.html#method.read_line">https://doc.rust-lang.org/std/io/trait.BufRead.html#method.read_line</a>&gt;</p>



<a name="245896127"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Stdin%20enhancements/near/245896127" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Yu [they/she] <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Stdin.20enhancements.html#245896127">(Jul 13 2021 at 22:10)</a>:</h4>
<p><span class="user-mention" data-user-id="239881">@Josh Triplett</span> updated stdin forwarders stuff: <a href="https://github.com/rust-lang/rust/pull/86847">https://github.com/rust-lang/rust/pull/86847</a> <a href="https://github.com/rust-lang/rust/issues/87096">https://github.com/rust-lang/rust/issues/87096</a></p>



<a name="245896194"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Stdin%20enhancements/near/245896194" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Stdin.20enhancements.html#245896194">(Jul 13 2021 at 22:10)</a>:</h4>
<p><span class="user-mention" data-user-id="411291">@Taylor Yu [they/she]</span> Stepping away for a bit, but <span aria-label="+1" class="emoji emoji-1f44d" role="img" title="+1">:+1:</span>, thank you for doing that work.</p>



<a name="245896201"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Stdin%20enhancements/near/245896201" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Stdin.20enhancements.html#245896201">(Jul 13 2021 at 22:10)</a>:</h4>
<p>No objections at this time.</p>



<a name="246672987"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Stdin%20enhancements/near/246672987" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Yu [they/she] <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Stdin.20enhancements.html#246672987">(Jul 21 2021 at 02:20)</a>:</h4>
<p><span class="user-mention" data-user-id="239881">@Josh Triplett</span> does anything else need to be done for <a href="https://github.com/rust-lang/rust/pull/86847">https://github.com/rust-lang/rust/pull/86847</a> ?</p>



<a name="246673042"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Stdin%20enhancements/near/246673042" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Stdin.20enhancements.html#246673042">(Jul 21 2021 at 02:21)</a>:</h4>
<p>Nope. Merging...</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>